/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.wpi.first.wpilibj.templates.commands;

import edu.wpi.first.wpilibj.smartdashboard.SmartDashboard;
import edu.wpi.first.wpilibj.templates.LogitechController;

/**
 *
 * @author Jarrod Risley
 */
public class ManualArmDrive extends CommandBase {
    
    /*
     * Global Class Variables
     */
    LogitechController coDriverController;
    private double commandedValue;
    
    public ManualArmDrive() {
        // Use requires() here to declare subsystem dependencies
        // eg. requires(chassis);
        
        requires(mainArm);
        
    } // end ManualArmDrive Constructor

    // Called just before this Command runs the first time
    protected void initialize() {
        coDriverController = oi.getCoDriverController();
        mainArm.disable();
    } // end initialize

    // Called repeatedly when this Command is scheduled to run
    protected void execute() {
        
        mainArm.setPosition(mainArm.getPosition() + (int) -coDriverController.scale(coDriverController.getRightY(), 1) * 1);
        SmartDashboard.putNumber("String Pot", mainArm.getLocation());
        commandedValue = -coDriverController.scale(coDriverController.getRightY(), 1);
        
        if (mainArm.getLocation() < 480 && mainArm.getLocation() > 50) {
            mainArm.manualOverride(commandedValue);
        } else if (mainArm.getLocation() > 480) {
            
            if (commandedValue > 0)
                mainArm.manualOverride(0);
            else if (commandedValue < 0) 
                mainArm.manualOverride(commandedValue);
            
        } else if (mainArm.getLocation() < 50) {
            
            if (commandedValue > 0)
                mainArm.manualOverride(commandedValue);
            else if (commandedValue < 0) 
                mainArm.manualOverride(0);
            
        } // end ....lots of ifs 
            
        
        
        
    } // end execute 

    // Make this return true when this Command no longer needs to run execute()
    protected boolean isFinished() {
        return false;
    } // end isFinished

    // Called once after isFinished returns true
    protected void end() {
    } // end end...lolz

    // Called when another command which requires one or more of the same
    // subsystems is scheduled to run
    protected void interrupted() {
        execute();
    } // end interrupted
    
} // end ManualArmDrive
